
import integrisign.desktop.DeskSign;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdom2.CDATA;
import org.jdom2.Element;
import sun.misc.UUEncoder;

/**
 * Clase encargada de generar la estructura principal del XML en el que se almacenaran
 * los datos del ePadink
 * @author epindado
 */

public class PlantillaXML extends Element {

        /**
         * Constructor que inicilizará una etiqueta del xml
         * @param atributo 
         */
        public PlantillaXML (String atributo){
            super (atributo);
        }

        /**
         * Creación de la plantilla del aparato ePad
         * @param deskSign
         * @param lfecha 
         */
        public void PlantillaXMLAparato(DeskSign deskSign, long lfecha) { 
            try {
                addContent(new Element("nombre").setText(deskSign.getSignerName())); 
                addContent(new Element("direccion").setText(deskSign.getSignerAddress())); 
                addContent(new Element("designacion").setText(deskSign.getSignerDesignation())); 
                addContent(new Element("organizacion").setText(deskSign.getSignerOrganisation())); 

                //Se decodifica el UID para que sea imprimible
                UUEncoder uudc = new UUEncoder();
                String cDataUID = uudc.encode(deskSign.getSignerUID().getBytes());
                addContent(new Element("UID").setContent(new CDATA(cDataUID)));

                addContent(new Element("fechaFirma").setText(new Date(lfecha).toString()));
                addContent(new Element("codigoPais").setText(deskSign.getLocale().getCountry()));
                addContent(new Element("Pais").setText(deskSign.getLocale().getDisplayName()));
                addContent(new Element("displayLanguage").setText(deskSign.getLocale().getDisplayLanguage()));
                addContent(new Element("firmado").setText((deskSign.isSigned()) ? "Si" : "No"));

                String cData = deskSign.getJpegString(deskSign.getString(), 100, 65, 85);
                addContent(new Element("imagen").setContent(new CDATA(cData)));

                addContent(new Element("clase").setText(deskSign.toString()));
                addContent(new Element("Base64").setText(deskSign.getString()));
            } catch (Exception ex) {
             Logger.getLogger(PlantillaXML.class.getName()).log(Level.SEVERE, null, ex);
            } 
        }

        /**
         * Creacion de la plantilla de datos de usuario
         * @param nombre 
         */
         public void PlantillaXMLCliente(String nombre) { 
            addContent(new Element("nombre").setText(nombre)); 
         }
}